﻿using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Linq;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;

using Microsoft.SharePoint.Workflow;
using Microsoft.SharePoint.WorkflowActions;

namespace WolverineCustomActivities
{
	public partial class ParseDouble_Activity: Activity
	{
        public static DependencyProperty __ContextProperty = DependencyProperty.Register("__Context", typeof(WorkflowContext), typeof(ParseDouble_Activity));
        public static DependencyProperty InputValueProperty = DependencyProperty.Register("InputValue", typeof(System.String), typeof(ParseDouble_Activity));
        public static DependencyProperty OutputValueProperty = DependencyProperty.Register("OutputValue", typeof(System.Double), typeof(ParseDouble_Activity));

        [Category("Wolverine Activities"), Browsable(true)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public WorkflowContext __Context
        {
            get
            {
                return (WorkflowContext)base.GetValue(ParseDouble_Activity.__ContextProperty);
            }
            set
            {
                base.SetValue(ParseDouble_Activity.__ContextProperty, value);
            }
        }
        [Category("Wolverine Activities"), Browsable(true)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public string InputValue
        {
            get
            {
                return (string)base.GetValue(ParseDouble_Activity.InputValueProperty);
            }
            set
            {
                base.SetValue(ParseDouble_Activity.InputValueProperty, value);
            }
        }
        [Category("Wolverine Activities"), Browsable(true)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public Double OutputValue
        {
            get
            {
                return (Double)base.GetValue(ParseDouble_Activity.OutputValueProperty);
            }
            set
            {
                base.SetValue(ParseDouble_Activity.OutputValueProperty, value);
            }
        }

        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            string _value = null;
            if (this.InputValue != null)
            {
                Activity parent = executionContext.Activity;
                while (parent.Parent != null)
                {
                    parent = parent.Parent;
                }
                _value = Helper.ProcessStringField(this.InputValue, parent, null);
            }
            this.OutputValue = Double.Parse(_value);
            return ActivityExecutionStatus.Closed;
        }

		public ParseDouble_Activity()
		{
			InitializeComponent();
		}
	}
}
